/*************************************************************************
	> File Name: tests/uart.c
	> Author: 
	> Mail: 
	> Created Time: 2020年12月15日 星期二 21时57分24秒
 ************************************************************************/

// #define UART_STATE (*(unsigned int*)0x00100008)
// #define UART_DATA  (*(unsigned int*)0x00100004)

#define UART_DATA  (*(unsigned int*)0x10000004)
#define UART_STATE (*(unsigned int*)0x10000008)

#define SW_BUTTON_REG (*(unsigned int*)0x10001000)

#define PWM_PERIOD_REG (*(unsigned int*)0x10002000)
#define PWM_DUTY_REG   (*(unsigned int*)0x10002004)

#define DIGITAL_CTRL_VAL (*(unsigned int*)0x10007000)
#define DIGITAL_CTRL_SEL (*(unsigned int*)0x10007004)

int uart_read(unsigned char* buf);
unsigned char uart_buf[1024];
int 		  uart_prt;

void _putc(unsigned char c)
{
	while(UART_STATE & 0x1);	
	UART_DATA = c;
}


void uart0_puts(char* str)
{
	while(*str != '\0') {
		_putc((unsigned char)(*str));
		str++;
	}
}

void button_release(unsigned int btn_vec)
{
	int btf ;//= SW_BUTTON_REG & 0x01;
	//Button Pressed Wait for release
	do{
		btf = SW_BUTTON_REG & btn_vec;
	}while(btf);
}


int judge_logic(unsigned char* usrname,int len) {
	return 0;
}

int verify(unsigned char* buf,int len)
{
	unsigned char usrname[20];
	for(int i=0;i < len ;i++) {
		usrname[i] = buf[i];
	}
	return judge_logic(usrname,len);
}


int main()
{	
	unsigned char buf[60];
	int len;
	int vret;
	while(1) {
		len = uart_read(buf);
		if(len != -1) 
			vret = verify(buf,len);
		
		if(!vret){
			uart0_puts("verify success\n");
		}
	}
	return 0;
}


